import numpy as np
from PIL import Image
import os
import random
from siamese import Siamese

# def get_test_imgs(path):
#
#
#     file = os.listdir(path)
#     file.sort(key=lambda x: int(x))
#     test_imgs = []
#     for character in file:
#         character_path = os.path.join(path, character)
#         for image in os.listdir(character_path):
#             test_imgs.append(os.path.join(character_path, image))
#
#     return test_imgs

def randint_digit(low, high, cutoff):
    """用来生成一个在区间[low, high)排除cutoff后的随机整数

    Parameters
    ----------
    low: int
        下限，能够取到
    high: int
        上限，不能够取到
    cutoff: int/list
        一个需要剔除的数或者数组，要求在(low, high)区间之间
    """
    digit_list = list(range(low, high))
    if type(cutoff) is int:  # 只需要剔除一个值
        if cutoff in digit_list:  # 如果需要剔除的值不存在，则不执行剔除操作
            digit_list.remove(cutoff)
    else:
        for i in cutoff:  # 需要剔除多个值的情况
            if i not in digit_list:  # 如果需要剔除的值不存在，则不执行剔除操作
                continue
            digit_list.remove(i)

    np.random.shuffle(digit_list)

    return digit_list.pop()  # 生成的序列打乱并且返回当前的随机值

if __name__ == "__main__":
    #
    model = Siamese()

    Q = os.listdir("ship/val/Q")
    Z = os.listdir("ship/val/Z")
    QList = []
    ZList = []
    T = 0
    F = 0

    for i in Q:
        imgname = os.path.join("ship/val/Q", i)
        image = Image.open(imgname)
        probability = model.detect_image(image)
        if probability == 0:
            T += 1
        else:
            F += 1

    for i in Z:
        imgname = os.path.join("ship/val/Z", i)
        ZList.append(imgname)
        image = Image.open(imgname)
        probability = model.detect_image(image)
        if probability == 1:
            T += 1
        else:
            F += 1

    result = T / (T + F)
    print("准确率：", result)
